package com.cqut.forum.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cqut.forum.service.ActiveService;
import com.cqut.forum.service.ModuleService;

@Controller
public class UserNewsAction {
	@Resource
	private ModuleService moduleService;
	@Resource
	private ActiveService activeService;
	
	@SuppressWarnings("deprecation")
	@RequestMapping("/news/get_visitor")
	@ResponseBody
	public List<Map<String, Object>> getModuleVisitors(int userId,String moduleName,int index,int size){
		int moduleIndex = moduleService.getModuleIndex(moduleName);
		List<Map<String, Object>> visitors = activeService.getModuleVisitors(userId, moduleIndex, index, size);
		List<Map<String, Object>> result = new ArrayList<Map<String,Object>>();
		for(Map<String, Object> m :visitors){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("userId", m.get("user_id"));
			map.put("userName", m.get("user_name"));
			map.put("userSex", m.get("user_sex"));
			map.put("userPhoto", m.get("user_photo"));
			map.put("visitTime", ((Date)m.get("news_time")).toLocaleString());
			
			result.add(map);
		}
		
		return result;
	}
	
	@RequestMapping("/news/visit_others")
	@ResponseBody
	public List<Map<String, Object>> getVisitOther(int userId,String moduleName,int index,int size){
		List<Map<String, Object>> result = new ArrayList<Map<String,Object>>();
		
		return result;
	}
	
	/*@RequestMapping("/news/get_message")
	@ResponseBody
	public List<Map<String, Object>> getMessages(HttpServletRequest request,int index,int size){
		User user = (User)request.getSession().getAttribute("user");
		List<Map<String, Object>> messages = userNewsService.getMessages(user.getUserId(),index,size);
		
		userNewsService.haveReadMyMessages(user.getUserId(),"留言");
		return messages;
	}*/
}
